package sender;

import java.util.Map;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;


public class EmailSenderJava {

	@SuppressWarnings("rawtypes")
	public static void sendMail(Map sender) throws EmailException {

		MultiPartEmail multipartemail = new MultiPartEmail();
		String etype=(String) sender.get("type");
		if(etype==null){
			return ;
		}
		if (etype.equals("qq")) {
			multipartemail.setHostName("smtp.qq.com");
		} else if (etype.equals("163")) {
			multipartemail.setHostName("smtp.163.com");
		} else if (etype.equals("gmail")) {
			multipartemail.setSSL(Boolean.TRUE);
			multipartemail.setSslSmtpPort("465");
			multipartemail.setHostName("smtp.gmail.com");
		} else {
			multipartemail.setSSL(Boolean.TRUE);
			multipartemail.setSslSmtpPort("465");
			multipartemail.setHostName("smtp.gmail.com");
		}
		multipartemail.addTo((String) sender.get("sendto"),
				(String) sender.get("username"));
		multipartemail.setFrom((String)sender.get("user"), (String)sender.get("name"));
		multipartemail.setAuthentication((String)sender.get("user"), (String)sender.get("psw"));
		multipartemail.setSubject((String)sender.get("subject"));
		multipartemail.setContent(sender.get("content"),
				"text/html;charset=GBK");
		multipartemail.send();


	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
